package com.example.springboot.controller;

import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
public class LoginController {


    @PostMapping("/user/login")
    public String checkLogin(@RequestParam("username") String username,
                             @RequestParam("password")String password,
                             Map<String,String> map, HttpServletRequest request){
        if(!StringUtils.isEmpty(username) && "123456".equals(password)){
            request.getSession().setAttribute("userInfo","userInfo");
            return "redirect:/index.html";
        }else{
            map.put("msg","用户名密码错误！");
            return "login";
        }
    }
}
